<?php

namespace Home\Controller;

use Think\Controller;
use \Model\EntityModel;
use \Model\SkillModel;
use \Model\OrderModel;
use Common\Common\UserGlobal;  //公共类

class OrderController extends CommonController
{

	//提交订单
	public function submit_order(){
		$data['order_skill_id'] = $_POST['skill_id'];	//技能Id
		$data['order_user_b_id'] = $_POST['user_b_id'];	//用户b id
		$data['order_user_b_start_address'] = $_POST['user_b_start_address']; //用户b 起始地址
		$data['order_user_b_end_address'] = $_POST['user_b_end_address'];	//用户b 结束地址
		$data['order_user_b_start_time'] = $_POST['user_b_start_time'];	//用户b 起始时间
		$data['order_user_b_end_time'] = $_POST['user_b_end_time'];		//用户b 结束时间
		$data['order_user_b_contact_way'] = $_POST['user_b_contact_way'];	//用户b 默认联系方式
		$data['order_user_b_contact_way_value'] = $_POST['user_b_contact_way_value'];	//用户b 默认联系方式值
		$data['order_user_b_note'] = $_POST['user_b_note'];//用户b 备注
		$data['order_price'] =  $_POST['order_price'];//订单价格
		//根据skill_id查询skill的详细信息
		$skillmodel = new SkillModel;
		$info = $skillmodel->model_get_skill_detail($data['order_skill_id']);

		//封装订单数据
		$data['order_user_a_id'] = $info['user_id'];
		$data['order_user_a_default_contact_way'] = $info['user_default_contact_way'];	//用户a默认联系方式
		if($info['user_default_contact_way'] == 1) {
			$data['order_user_a_default_contact_way_value'] = $info['user_tel'];
		}else if($info['user_default_contact_way'] == 2) {
			$data['order_user_a_default_contact_way_value'] = $info['user_qq'];
		}else if($info['user_default_contact_way'] == 3) {
			$data['order_user_a_default_contact_way_value'] = $info['user_wechat'];
		}

		//封装订单的其他信息
		$data['order_time'] = date('Y-m-d H:i:s', time());
		$data['order_number'] = 'S'.date('YmdHis', time()).sprintf("%08d",$data['order_skill_id']);
		$data['order_state'] = 2;
		
		$ordermodel = new OrderModel;
		$ordermodel->model_submit_skill_order($data);
	}

	//获取用户b 等待接单的订单
	public function get_user_b_await_order() {
		$user_b_id = $_GET['user_b_id'];
		$ordermodel = new OrderModel;
		$info = $ordermodel->model_get_user_a_await_order('b', $user_b_id, 2);	//获取订单状态为2
		echo json_encode($info);
	
	}

	
	//获取用户a 等待接单的订单
	public function get_user_a_await_order() {
		$user_a_id = $_GET['user_a_id'];
		$ordermodel = new OrderModel;
		$info = $ordermodel->model_get_user_a_await_order('a', $user_a_id, 2);	//获取订单状态为2
		echo json_encode($info);
	
	}


	//获取用户b 共享中的订单
	public function get_user_b_sharing_order() {
		$user_b_id = $_GET['user_b_id'];
		$ordermodel = new OrderModel;
		$info = $ordermodel->model_get_user_a_await_order('b', $user_b_id, 3);	//获取订单状态为3
		echo json_encode($info);
	
	}

	
	//获取用户a 共享中的订单
	public function get_user_a_sharing_order() {
		$user_a_id = $_GET['user_a_id'];
		$ordermodel = new OrderModel;
		$info = $ordermodel->model_get_user_a_await_order('a', $user_a_id, 3);	//获取订单状态为3
		echo json_encode($info);
	
	}




}